<?php
	require_once("Enzyme.php");

	class EditEnzymeController{

		var $clientOrig;
		var $nameOrig;
		var $originOrig;
		var $dateOrig;

		var $client;
		var $name;
		var $origin;
		var $date;
		
		var $flag;
		
		function getEnzymeData(){
			$this->clientOrig = $_REQUEST['clientOrig'];
			$this->nameOrig = $_REQUEST['nameOrig'];
			$this->originOrig = $_REQUEST['originOrig'];
			$this->dateOrig = $_REQUEST['dateOrig'];
			
			$this->client = $_REQUEST['client'];
			$this->name = $_REQUEST['name'];
			$this->origin = $_REQUEST['origin'];
			$this->date = $_REQUEST['date'];
			
			$this->flag = $_REQUEST['flag'];
		}
		
		function retrieveClient(){
			$edit="edit";
			$enzyme = new Enzyme;
			$enzyme->retrieve($edit);
		}
		function retrieveEnzymeInfo($client, $name){
			$enzyme = new Enzyme;
			$enzyme->viewInfo($client, $name);
		}

	}
	
	
	$editEnzymeController = new editEnzymeController;
	$editEnzymeController->getEnzymeData();
	
	if($editEnzymeController->flag=="load"){
		$editEnzymeController->retrieveClient();
	}
	elseif($editEnzymeController->flag=="selectEnzyme"){
		$editEnzymeController->retrieveEnzymeInfo($editEnzymeController->client,$editEnzymeController->name);
	}
	elseif($editEnzymeController->flag=="submit"){
			echo "	<script>";

			echo "		client2 = \"".$editEnzymeController->clientOrig."\";";
			echo "		name2 = \"".$editEnzymeController->nameOrig."\";";
			echo "		origin2 = \"".$editEnzymeController->originOrig."\";";
			echo "		date2 = \"".$editEnzymeController->dateOrig."\";";
			
			echo "		client = \"".$editEnzymeController->client."\";";
			echo "		name = \"".$editEnzymeController->name."\";";
			echo "		origin = \"".$editEnzymeController->origin."\";";
			echo "		date = \"".$editEnzymeController->date."\";";
			
			echo "		from = \"confirm\";";
			
			echo "		$.post('viewEnzymeInfo.php',{";
			
			echo "			clientOrig: client2,";
			echo "			nameOrig: name2,";
			echo "			originOrig: origin2,";
			echo "			dateOrig: date2,";
			
			echo "			client: client,";
			echo "			name: name,";
			echo "			origin: origin,";
			echo "			date: date,";

			echo "			from:from";
			echo "			},function(data){";
			echo "				$('#view').html(data);";
			echo "			}";
			echo "		);";
			echo "	</script>";
	}
	elseif($editEnzymeController->flag=="confirm"){
		$enzyme = new Enzyme();
		$enzyme->sendEnzymeDetails($editEnzymeController->clientOrig, $editEnzymeController->nameOrig, $editEnzymeController->client, $editEnzymeController->name, $editEnzymeController->origin, $editEnzymeController->date);
		$enzyme->edit();
	}
	elseif($editEnzymeController->flag=="editEditClient"){
		$editEnzymeController->getClientData();
		echo "<input type=\"hidden\" id=\"client\' value=\"".$editEnzymeController->client."\" >";
		echo "Name<br /><input type='text' name='company' value=\"".$editEnzymeController->name."\" id='company' /><br />";
		echo "Place of Origin<br /><input type='text' name='address' value=\"".$editEnzymeController->origin."\" id='address' /><br />";
		echo "Test Procedure<br /><input type='text' name='cellNo' value=\"".$editEnzymeController->test."\" id='cellNo' /><br />";
		echo "Date Submitted<br /><input type='text' name='telNo' value=\"".$editEnzymeController->date."\" id='telNo' /><br />";
		echo "<input type='button' value='Submit' id='buttonSubmit' onclick=\"editClientData('editSelectedClient');return false;\" />";	
		echo "<input type='button' value='Cancel' id='buttonCancel' onclick='cancel();return false;' />";
	}	
	
	

?>